Repository navigation
refactor(api): migrate ToJSON instances to use experimental Era type - #1038
Merged
newhoggy merged 1 commit intoNov 26, 2025
Merged
Conversation
newhoggy
requested review from
CarlosLopezDeLara,
Jimbo4350,
carbolymer,
dcoutts,
disassembler,
erikd,
kevinhammond and
palas
as code owners
November 25, 2025 11:01
carbolymer
reviewed
Nov 26, 2025
| prop_json_roundtrip_utxo :: Property | ||
| prop_json_roundtrip_utxo = H.property $ do | ||
| utxo <- forAll $ genUTxO ShelleyBasedEraBabbage | ||
| utxo <- forAll $ genUTxO ShelleyBasedEraConway |
Contributor
There was a problem hiding this comment.
The era should be defined and reused at the top level.
carbolymer
approved these changes
Nov 26, 2025
Replaces IsCardanoEra constraint with Exp.IsEra in ToJSON instances for TxOut and UTxO types, adopting the new experimental Era framework for JSON serialization. This change simplifies the era handling by using Exp.useEra instead of cardanoEra and reduces the pattern matching cases in txOutToJsonValue to only handle ConwayEra and DijkstraEra. - Update TxOut ToJSON instance to use Exp.IsEra constraint - Update UTxO ToJSON instance to use Exp.IsEra constraint - Refactor txOutToJsonValue to use Exp.Era type parameter - Remove redundant pattern matches for Byron through Babbage eras - Update test generators to use ShelleyBasedEraConway instead of Babbage The test suite changes ensure compatibility with the new era handling approach by testing against the Conway era, which provides better coverage of the current serialization logic.
newhoggy
force-pushed
the
newhoggy/modify-some-ToJSON-instances-to-use-IsEra
branch
from
November 26, 2025 11:16
6708242 to
21408c8
Compare
newhoggy
enabled auto-merge
November 26, 2025 11:16
carbolymer
approved these changes
Nov 26, 2025
newhoggy
deleted the
newhoggy/modify-some-ToJSON-instances-to-use-IsEra
branch
November 26, 2025 13:10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog
Context
This PR refactors the JSON serialization logic for
TxOutandUTxOtypes to adopt the experimental Era framework (Cardano.Api.Experimental.Era). The change replaces theIsCardanoEraconstraint withExp.IsEra, providing a cleaner and more maintainable approach to era-specific serialization.The refactoring significantly reduces the complexity of
txOutToJsonValueby eliminating redundant pattern matches for historical eras (Byron through Babbage) that share identical serialization logic, keeping only the distinct implementations for Conway and Dijkstra eras.How to trust this PR
The changes are purely refactoring with no functional changes to the JSON output format. Key areas to review:
IsCardanoEra era => ToJSONbecomesExp.IsEra era => ToJSONin bothTxOutandUTxOmodulestxOutToJsonValuefunction now only handlesExp.ConwayEraandExp.DijkstraEra, removing 6 redundant case branchesShelleyBasedEraConwayinstead ofShelleyBasedEraBabbagefor better coverageTo verify the changes preserve existing behavior:
Checklist